package com.monkey.core.domain.code;

import com.monkey.core.domain.BaseEntity;
import com.monkey.core.plugin.dto.MonkeyDto;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * Project  : monkey
 * Author   : Wu Tian Qiang
 * Date     : 2016/9/12
 */
@Entity
@Table(name = "sys_code_temple")
@DynamicUpdate
@DynamicInsert
public class CodeTemplate extends BaseEntity<Long> {
    private String name;

    @Column(name = "package_path")
    private String packagePath;

    @Column(name = "class_name")
    private String className;
    private String picture;
    private String view;
    private String remark;

    public CodeTemplate() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getView() {
        return view;
    }

    public void setView(String view) {
        this.view = view;
    }

    public String getPackagePath() {
        return packagePath;
    }

    public void setPackagePath(String packagePath) {
        this.packagePath = packagePath;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public static CodeTemplate createFromMonkeyDto(MonkeyDto monkeyDto) {
        CodeTemplate codeTemplate = new CodeTemplate();
        codeTemplate.setRemark(monkeyDto.getString("remark"));
        codeTemplate.setClassName(monkeyDto.getString("className"));
        codeTemplate.setName(monkeyDto.getString("name"));
        codeTemplate.setPackagePath(monkeyDto.getString("packagePath"));
        codeTemplate.setView(monkeyDto.getString("view"));
        return codeTemplate;
    }

    public static void modifyFromMonkeyDto(CodeTemplate template, MonkeyDto monkeyDto) {
        template.setRemark(monkeyDto.getString("remark"));
        template.setClassName(monkeyDto.getString("className"));
        template.setName(monkeyDto.getString("name"));
        template.setPackagePath(monkeyDto.getString("packagePath"));
        template.setView(monkeyDto.getString("view"));
    }

}
